/*
Copyright (C) 1996-1997 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

#include "quakedef.h"
#include "menu.shared.h"


class qmenu_slist_t : public qmenu_t
{
public:
	qmenu_slist_t (void)
	{
		this->AddOption (new qmenu_banner_t ("gfx/p_multi.lmp"));
		this->AddOption (new qmenu_divider_t ());
		this->Register (m_slist);
	}

	void EnterFunc (void)
	{
		/*
		this->EnterMenu ();

		m_return_onerror = FALSE;
		m_return_reason[0] = 0;
		slist_sorted = FALSE;

		this->cursor = 0;
		this->maxitems = hostCacheCount;
		*/
	}

	BOOL KeyFunc (int key)
	{
		/*
		switch (key)
		{
		case K_ESCAPE:
			this->LeaveMenu ();
			break;

		case K_SPACE:
			menus[m_search]->EnterFunc ();
			break;

		case K_UPARROW:
		case K_LEFTARROW:
			this->Navigate (-1);
			break;

		case K_DOWNARROW:
		case K_RIGHTARROW:
			this->Navigate (1);
			break;

		case K_ENTER:
			m_return_state = m_state;
			m_return_onerror = TRUE;
			slist_sorted = FALSE;
			Key_SetDest (key_game);
			m_state = m_none;
			Cbuf_AddText (va ("connect \"%s\"\n", hostcache[this->cursor].cname));
			break;

		default:
			break;
		}

		return TRUE;
		*/

		return FALSE;
	}

protected:
	void CustomDraw (void)
	{
		/*
		if (!slist_sorted)
		{
			if (hostCacheCount > 1)
			{
				hostcache_t temp;

				for (int i = 0; i < hostCacheCount; i++)
				{
					for (int j = i + 1; j < hostCacheCount; j++)
					{
						if (strcmp (hostcache[j].name, hostcache[i].name) < 0)
						{
							Q_memcpy (&temp, &hostcache[j], sizeof (hostcache_t));
							Q_memcpy (&hostcache[j], &hostcache[i], sizeof (hostcache_t));
							Q_memcpy (&hostcache[i], &temp, sizeof (hostcache_t));
						}
					}
				}
			}

			slist_sorted = TRUE;
		}

		for (int n = 0; n < hostCacheCount; n++)
		{
			char string[64];

			if (hostcache[n].maxusers)
				sprintf (string, "%-15.15s %-15.15s %2u/%2u\n", hostcache[n].name, hostcache[n].map, hostcache[n].users, hostcache[n].maxusers);
			else sprintf (string, "%-15.15s %-15.15s\n", hostcache[n].name, hostcache[n].map);

			M_Print (16, 32 + 8 * n, string);
		}

		M_DrawSmallCursor (0, 32 + this->cursor * 8);

		if (*m_return_reason)
			M_PrintWhite (160 - strlen (m_return_reason) * 4, 148, m_return_reason);
		*/
	}

private:
	BOOL slist_sorted;
} menu_slist;


